<template>
    <el-form :model="users" style="width: 500px;">
        <el-form-item label="用户名">
            <el-input v-model="users.name" />
        </el-form-item>
        <el-form-item label="密码">
            <el-input v-model="users.pwd" show-password />
        </el-form-item>
        <el-form-item>
            <el-button type="primary" @click="LoginUser">登录</el-button>
        </el-form-item>


    </el-form>
</template>

<script setup lang="ts">
import { ref, inject, onMounted } from 'vue'
import { ElMessage, ElMessageBox } from 'element-plus';
import { useRouter, useRoute } from 'vue-router'
import { type AxiosStatic } from 'axios'


const axios = inject('axios') as AxiosStatic
const router = useRouter()
const route = useRoute()

//用户登录
const users = ref({
    name: '',
    pwd: '',
})
//登录
const LoginUser = () => {
    axios.get('/RbacMan/LoginUser', {
        params: {
            name: users.value.name,
            pwd: users.value.pwd
        }
    }).then(res => {

        console.log(res.data);
        if (res.data.usersId !== null) {
            ElMessage.success("登录成功")
            localStorage.setItem("roleId", res.data.roleId)
            router.push({
                name: 'Mainindex',
                // query: {
                //     roleId: res.data.roleId
                // }
            })
        } else {

            ElMessage.error("登录失败")
            return
        }
    })
}


</script>